//
//  ViewController.m
//  UI_09_homework_UiTableVIew_省市区
//
//  Created by li cheng on 16/7/26.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"
#import "VCOfCity.h"

@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *provinces;
@property (nonatomic, strong) NSArray *lineArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *sourceOfString = [NSString stringWithContentsOfFile:@"/Users/licheng/DLS10710/UI/HomeWork/UI_09_homework_UiTableVIew_省市区/UI_09_homework_UiTableVIew_省市区/area.txt" encoding:NSUTF8StringEncoding error:nil];
    self.lineArray = [sourceOfString componentsSeparatedByString:@"\n"];
    // 创建一个可变的数组,用来存储每个省
    self.provinces = [NSMutableArray array];
    // 遍历每一行字符串
    for (NSString *string in self.lineArray) {
        if (![string hasPrefix:@"  "]) {
            [self.provinces addObject:string];
        }
    }
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _provinces.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    cell.textLabel.text = _provinces[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    VCOfCity *vcOfCity = [[VCOfCity alloc] init];
    vcOfCity.lineArray = self.lineArray;
    vcOfCity.row = indexPath.row;
    [self.navigationController pushViewController:vcOfCity animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
